package com.kclmedu.sst.security;

import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/*****************************8
 *  自定义认证的凭证来源，我们此处通过  UserDetails 接口来做为来源
 */
public class SimpleUserDetailsService implements UserDetailsService {

    /*************************
     * 加载用户信息
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //User 类型实现了 UserDetails接口
        User user = new User("yejf", "123456",
                AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));

        System.out.printf("----> 调用了loadUserByUsername(%s)\n", username);
        //返回
        return user;
    }
}
